function rollToTop(page: Element) {
  if (page?.scrollTop) {
    if (page.scrollTop < 20) {
      page.scrollTop = 0;
    }
    else {
      page.scrollTo(0, page.scrollTop / 3); // 每次滚动一小段距离
      window.requestAnimationFrame(() => rollToTop(page)); // 请求下一帧动画
    }
  }
}
export function toTop(page: Element) {
  // 启动滚动条回到顶部的动画
  window.requestAnimationFrame(() => rollToTop(page));
}
export default defineNuxtRouteMiddleware((to, from) => {
  if (import.meta.client) {
    const page = document.querySelector("#theMain")!;
    toTop(page);
    console.log("go ahead");
    console.log(`'${from.path}' -> '${to.path}'`);
  }
});
